package com.sun.common.core.utils;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;


public class SimpleConverter {
    private static final Logger log = LoggerFactory.getLogger(SimpleConverter.class);

    public SimpleConverter() {
    }

    public static void copyProperties(Object orig, Object dest) {
        BeanUtils.copyProperties(orig, dest);
    }

    public static <T> T convert(Object orig, Class<T> dest) {
        return convert(orig, dest, (String[]) null);
    }

    public static <T> T convert(Object orig, Class<T> dest, String... ignoreProperties) {
        if (Objects.isNull(orig)) {
            return null;
        } else {
            T obj = null;

            try {
                obj = dest.newInstance();
                BeanUtils.copyProperties(orig, obj, ignoreProperties);
                return obj;
            } catch (Exception var5) {
                Exception e = var5;
                throw new RuntimeException(MessageFormat.format("Convert error: {0} to {1}", orig, obj), e);
            }
        }
    }

    public static <F, T> List<T> convert(List<F> orig, Class<T> dest) {
        if (Objects.isNull(orig)) {
            return null;
        } else {
            List<T> list = new ArrayList();
            Iterator var3 = orig.iterator();

            while (var3.hasNext()) {
                F o = (F) var3.next();
                T t = convert(o, dest);
                list.add(t);
            }

            return list;
        }
    }
}
